package cn.shyouchi.wuguanjia.android.ui.event.arrange;

import android.os.Parcel;
import android.os.Parcelable;

import com.chad.library.adapter.base.entity.AbstractExpandableItem;
import com.chad.library.adapter.base.entity.MultiItemEntity;

import java.util.ArrayList;
import java.util.List;

import cn.shyouchi.wuguanjia.android.ui.event.checknum.CheckNumLineEntity;
import cn.shyouchi.wuguanjia.android.ui.event.labor.LaborRequestEntity;
import cn.shyouchi.wuguanjia.android.ui.event.labor.PersonRank;

/**
 * Created by Eenie on 2016/11/26 21:10.
 * Des:
 */


public class PersonRankAdapter implements Parcelable {


    private Person person;
    private List<Rank> ranks = new ArrayList<>();
    private boolean isChecked = false;

    public PersonRankAdapter(PersonRank.ResultMessageBean bean) {
        setPerson(new Person(bean.getUser_id(), bean.getUser_name(),null));
        List<Rank> ranks = new ArrayList<>();
        for (PersonRank.ResultMessageBean.InfoBean info : bean.getInfo()) {
            ranks.add(new Rank(info.getService().getId(), info.getService().getServicesname(), info.getDay()));
        }
        setRanks(ranks);
    }

    public Person getPerson() {
        return person;
    }

    public void setPerson(Person person) {
        this.person = person;
    }

    public List<Rank> getRanks() {
        return ranks;
    }

    public void setRanks(List<Rank> ranks) {
        this.ranks = ranks;
    }

    public boolean isChecked() {
        return isChecked;
    }

    public void setChecked(boolean checked) {
        isChecked = checked;
    }


    public int getRankCount(int id) {
        for (Rank rank : this.ranks) {
            if (rank.getRank_id() == id) {
                return rank.getRank_count();
            }
        }
        return 0;
    }

    public static class Person extends AbstractExpandableItem<LaborRequestEntity.ResultMessageBean.ServiceBeanX> implements MultiItemEntity, Parcelable {

        private int user_id;
        private String user_name;
        private CheckNumLineEntity.ResultMessageBean line;

        public Person(int id, String name,CheckNumLineEntity.ResultMessageBean line) {
            this.user_id = id;
            this.user_name = name;
            this.line = line;
        }

        public CheckNumLineEntity.ResultMessageBean getLine() {
            return line;
        }

        public void setLine(CheckNumLineEntity.ResultMessageBean line) {
            this.line = line;
        }

        private Object tag;

        public String getUser_name() {
            return user_name;
        }

        public void setUser_name(String user_name) {
            this.user_name = user_name;
        }

        public int getUser_id() {
            return user_id;
        }

        public void setUser_id(int user_id) {
            this.user_id = user_id;
        }




        @Override
        public int getItemType() {
            return RankAdapter.RANK_TYPE_SUBITEM;
        }

        public Object getTag() {
            return tag;
        }

        public void setTag(Object tag) {
            this.tag = tag;
        }

        @Override
        public int getLevel() {
            return 0;
        }

        @Override
        public int describeContents() {
            return 0;
        }

        @Override
        public void writeToParcel(Parcel dest, int flags) {
            dest.writeInt(this.user_id);
            dest.writeString(this.user_name);
            dest.writeParcelable(this.line, flags);

        }

        protected Person(Parcel in) {
            this.user_id = in.readInt();
            this.user_name = in.readString();
            this.line = in.readParcelable(CheckNumLineEntity.ResultMessageBean.class.getClassLoader());

        }

        public static final Creator<Person> CREATOR = new Creator<Person>() {
            @Override
            public Person createFromParcel(Parcel source) {
                return new Person(source);
            }

            @Override
            public Person[] newArray(int size) {
                return new Person[size];
            }
        };
    }


    public static class Rank implements Parcelable {

        public Rank(int id, String name, int count) {
            this.rank_id = id;
            this.rank_name = name;
            this.rank_count = count;
        }

        private int rank_id;
        private String rank_name;
        private int rank_count;

        public int getRank_id() {
            return rank_id;
        }

        public void setRank_id(int rank_id) {
            this.rank_id = rank_id;
        }

        public String getRank_name() {
            return rank_name;
        }

        public void setRank_name(String rank_name) {
            this.rank_name = rank_name;
        }

        public int getRank_count() {
            return rank_count;
        }

        public void setRank_count(int rank_count) {
            this.rank_count = rank_count;
        }

        @Override
        public int describeContents() {
            return 0;
        }

        @Override
        public void writeToParcel(Parcel dest, int flags) {
            dest.writeInt(this.rank_id);
            dest.writeString(this.rank_name);
            dest.writeInt(this.rank_count);
        }

        protected Rank(Parcel in) {
            this.rank_id = in.readInt();
            this.rank_name = in.readString();
            this.rank_count = in.readInt();
        }

        public static final Parcelable.Creator<Rank> CREATOR = new Parcelable.Creator<Rank>() {
            @Override
            public Rank createFromParcel(Parcel source) {
                return new Rank(source);
            }

            @Override
            public Rank[] newArray(int size) {
                return new Rank[size];
            }
        };
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeParcelable(this.person, flags);
        dest.writeTypedList(this.ranks);
        dest.writeByte(this.isChecked ? (byte) 1 : (byte) 0);
    }

    protected PersonRankAdapter(Parcel in) {
        this.person = in.readParcelable(Person.class.getClassLoader());
        this.ranks = in.createTypedArrayList(Rank.CREATOR);
        this.isChecked = in.readByte() != 0;
    }

    public static final Parcelable.Creator<PersonRankAdapter> CREATOR = new Parcelable.Creator<PersonRankAdapter>() {
        @Override
        public PersonRankAdapter createFromParcel(Parcel source) {
            return new PersonRankAdapter(source);
        }

        @Override
        public PersonRankAdapter[] newArray(int size) {
            return new PersonRankAdapter[size];
        }
    };
}


